<?php
namespace app\api\controller\deerhome\shop;

use app\api\controller\deerhome\shop\BaseAuth;
use think\Db;
use think\Validate;
use app\admin\model\deerhome\Shop as ShopModel;

/**
 * 门店
 */
class Shop extends BaseAuth
{
    public function set_time()
    {
        $id=$this->request->param("id",0,"intval");
        $s=$this->request->param("s","","trim");
        $e=$this->request->param("e","","trim");
        if(!preg_match("/^\d{2}:\d{2}$/",$s)){
            $this->err("开始时间格式错误");
        }
        if(!preg_match("/^\d{2}:\d{2}$/",$e)){
            $this->err("结束时间格式错误");
        }
        $shop=ShopModel::where("id",$id)->where('status',1)->where("deerhome_user_id",$this->_user['id'])->find();
        if(!$shop){
            $this->err("门店已被停用",1);
        }
        $shop->open_time=$s;
        $shop->close_time=$e;
        $shop->save();
        $this->ok($shop);
    }
    public function my()
    {
        $shop=ShopModel::where('status',1)->where("deerhome_user_id",$this->_user['id'])->select();
        $this->ok($shop);
    }
    public function detail()
    {
        $id=$this->request->param("id",0,"intval");
        $shop=ShopModel::where("id",$id)->where('status',1)->where("deerhome_user_id",$this->_user['id'])->find();
        if(!$shop){
            $this->err("门店已被停用",1);
        }
        $this->ok($shop);
    }
  
}
